package com.example.demo;

import com.example.demo.commom.AjaxResult;
import com.example.demo.controller.CommentController;
import com.example.demo.model.dto.comment.OpCommentDto;
import com.example.demo.model.dto.comment.OpCommentListDto;
import com.example.demo.model.dto.comment.PCommentDto;
import com.example.demo.model.dto.comment.SCommentDto;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockHttpServletRequest;

import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2024-05-31
 * Time:14:35
 */
@SpringBootTest
public class Comment {
    @Autowired
    private CommentController controller;

    private String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjIiLCJleHAiOjE3MTc0MTE2MzksInVzZXJuYW1lIjoiY3lrIn0.OjYGxtjLo0fdZBQkNj-P70r7RQ4OezLr8dIWQBL51Ig";

    @Test
    public void pubPComment(){
        HttpServletRequest request = new MockHttpServletRequest();
        request.setAttribute("token", token);
        PCommentDto dto = new PCommentDto();
        dto.setTarget_id(3);
        dto.setContent("写得好");
        AjaxResult result = controller.pubPComment(request, dto);
        System.out.println(result);
    }
    @Test
    public void pubSComment(){
        HttpServletRequest request = new MockHttpServletRequest();
        request.setAttribute("token", token);
        SCommentDto dto = new SCommentDto();
        dto.setTarget_id(1);
        dto.setContent("写得好hhhh");
        dto.setParent_id(3);
        AjaxResult result = controller.pubSComment(request, dto);
        System.out.println(result);
    }
    @Test
    public void listPComment(){
        AjaxResult result = controller.listPComment(0,0,3);
        System.out.println(result);
    }
    @Test
    public void listSComment(){
        AjaxResult result = controller.listSComment(0,0,2);
        System.out.println(result);
    }
    @Test
    public void delPComment(){
        HttpServletRequest request = new MockHttpServletRequest();
        request.setAttribute("token", token);
        OpCommentDto dto = new OpCommentDto();
        dto.setId(5);
        AjaxResult result = controller.delPComment(request, dto);
        System.out.println(result);
    }
    @Test
    public void delSComment(){
        HttpServletRequest request = new MockHttpServletRequest();
        request.setAttribute("token", token);
        OpCommentDto dto = new OpCommentDto();
        dto.setId(2);
        AjaxResult result = controller.delSComment(request, dto);
        System.out.println(result);
    }
}
